<?php
namespace app\admin\controller;
use \think\Controller;
use app\admin\model\Info as InfoModel;

class Index extends Controller
{
    
    protected $InfoModel;

    public function __construct()
    {
        if(!session('adminId')){
            $this->redirect('login/index');
        }
        $this->InfoModel = new InfoModel();
        $this->gid = session('adminGid');
    }

    public function index()
    {   
        $infoRes = $this->InfoModel->where('gid',$this->gid)->find();
        if(request()->isPost()){
            $data = input();
            $InfoRes = $infoRes -> save($data);
            if($InfoRes){
                $this->success('修改成功！','index/index'); 
            }
        }
        return view('index',[
            'info' => $infoRes
        ]);
    }

    public function upload(){
        $fileinfo = $_FILES['file'];
        $file = request()->file('file');
        $info = $file-> move(env('ROOT_PATH').'public/uploads');
        $image = str_replace('\\','/',$info->getSaveName()); 
        print_r($image);
    }

}
